package com.ruoyi.oa.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.oa.domain.OaHumanSalary;
import com.ruoyi.oa.domain.vo.OaHumanSalaryVo;
import com.ruoyi.oa.domain.bo.OaHumanSalaryBo;
import com.ruoyi.oa.service.IOaHumanSalaryService;
import com.ruoyi.common.core.page.TableDataInfo;


/**
 * 调薪申请
 *
 * @author ruoyi
 * @date 2023-06-30
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/oa/humanSalary")
public class OaHumanSalaryController extends BaseController {

    private final IOaHumanSalaryService iOaHumanSalaryService;

    /**
     * 查询调薪申请列表
     */
    @SaCheckPermission("oa:employeeInfo:list")
    @GetMapping("/list")
    public TableDataInfo<OaHumanSalaryVo> list(OaHumanSalaryBo bo, PageQuery pageQuery) {
        return iOaHumanSalaryService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出调薪申请列表
     */
    @SaCheckPermission("oa:employeeInfo:export")
    @Log(title = "调薪申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(OaHumanSalaryBo bo, HttpServletResponse response) {
        List<OaHumanSalaryVo> list = iOaHumanSalaryService.queryList(bo);
        ExcelUtil.exportExcel(list, "调薪申请", OaHumanSalaryVo.class, response);
    }

    /**
     * 获取调薪申请详细信息
     *
     * @param id 主键
     */
//    @SaCheckPermission("oa:employeeInfo:query")
    @GetMapping("/{id}")
    public R<OaHumanSalaryVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iOaHumanSalaryService.queryById(id));
    }

    /**
     * 新增调薪申请
     */
    @SaCheckPermission("oa:employeeInfo:add")
    @Log(title = "调薪申请", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<OaHumanSalaryBo> add(@Validated(AddGroup.class) @RequestBody OaHumanSalaryBo bo) {
        return R.ok(iOaHumanSalaryService.insertByBo(bo));
    }

    /**
     * 修改调薪申请
     */
    @SaCheckPermission("oa:employeeInfo:edit")
    @Log(title = "调薪申请", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<OaHumanSalary> edit(@Validated(EditGroup.class) @RequestBody OaHumanSalaryBo bo) {
        return R.ok(iOaHumanSalaryService.updateByBo(bo));
    }

    /**
     * 删除调薪申请
     *
     * @param ids 主键串
     */
    @SaCheckPermission("oa:employeeInfo:remove")
    @Log(title = "调薪申请", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(iOaHumanSalaryService.deleteWithValidByIds(Arrays.asList(ids), true));
    }

}
